import React from 'react';
import {
  Form,
  Input,
  Button,
  Table,
  Icon,
  Radio,
  InputNumber,
  Checkbox,
  Modal,
  message,
  notification,
  Affix,
  Upload,
  Select,
  Menu,
  Dropdown
} from 'antd';

import InnerTable from 'components/DBTable/InnerTable.js';
import ajax from '../../../utils/ajax';

const FormItem = Form.Item;
const ButtonGroup = Button.Group;
const Option = Select.Option;

var _this;

/**
 * 内部表格组件
 */
class ImageManageInnerTable extends InnerTable {

  /**
   * 构造器，好像是用来初始化的？
   * @param props
   */
  constructor(props) {
    super(props);
    this.state = {
      ...this.state,
    }
  }

  onClickView = (e) =>{
    // console.log("点击查看啦");
    e.preventDefault();
    this.resetFields();
    // console.log("this.state 里面的数据是", this.state);
    let selectedRowsPop = this.state.selectedRows[0];
    
    console.log("selectedRowsPop 里面的数据是", selectedRowsPop);

    
    // console.log("this.props.form 里面的数据是", this.props.form.getFieldsValue);
    if(selectedRowsPop){
      let defaultFileObj = [];
      let defaultFileItem = {};
      defaultFileItem.uid = selectedRowsPop.id;
      defaultFileItem.size = selectedRowsPop.size;
      defaultFileItem.key = selectedRowsPop.key;
      defaultFileItem.imgUrl = selectedRowsPop.imgUrl;
      defaultFileItem.width = selectedRowsPop.width + '*' + selectedRowsPop.height;
      defaultFileObj.push(defaultFileItem);

      this.setState({fileObjs : defaultFileObj});
    }

    var state={ modalVisible: true, modalTitle: '查看', modalState: this.modalActionState.View,modalForm:true};

    this.setState(state,()=>{
      this.props.look(selectedRowsPop);
      // this.props.form.setFieldsValue(selectedRowsPop);
    });
  }

  /**
   * 这里好像是用来配置那些按钮之类的
   * @returns {Array}
   */
  prepareBeforeToolBar = function () {
    let isButtondisabled = false;

    if (this.state.selectedRowKeys.length > 0) {  // 是否选择
      isButtondisabled = true;
    }

    if (this.state.selectedRowKeys.length > 1) {  // 是否选择了多项
      isButtondisabled = false;
    }

    //上面是选择框的那个配置
    var items = [];
    items.push(<Button key='look' onClick={this.onClickView} disabled={!isButtondisabled} ><Icon type="info-circle-o" />查看</Button>);

    return items;
  }

  handleModalOk = () => {
    this.setState({ modalVisible: false });
    this.props.refresh();
  }

  prepareModalInfo = () => {
    // 生成表单项
    const formItems = [];
    this.props.formSchema.forEach((field) => {
      if(this.enableFieldToFrom(field))
      {
          var converter = this.getConverter();
          this.preDealData(this.state.resData, field);
          formItems.push(converter.convert(this, field));
      }
    });
    return (<div className="innerTableCon"><Form layout="horizontal">{formItems}</Form></div>);
  }

  lookForm = () =>{
    const formItems = [];
    this.props.lookForm.forEach((field,i) => {
      if(this.enableFieldToFrom(field))
      {
          var converter = this.getConverter();
          this.preDealData(this.state.resData, field);
          formItems.push(converter.convert(this, field));
      }
    });
    return (<div className="innerTableCon"><Form layout="horizontal">{formItems}</Form></div>);

  }



}

export default ImageManageInnerTable;
